/**
 * 
 * This Javascript library was created by engineers from www.vercalendario.info. 
 * Copyright 2013 www.vercalendario.info. All rights reserved
 */
document.title=chrome.i18n.getMessage("extname");

    var mnames=[
        chrome.i18n.getMessage("m1"),
        chrome.i18n.getMessage("m2"),
        chrome.i18n.getMessage("m3"),
        chrome.i18n.getMessage("m4"),
        chrome.i18n.getMessage("m5"),
        chrome.i18n.getMessage("m6"),
        chrome.i18n.getMessage("m7"),
        chrome.i18n.getMessage("m8"),
        chrome.i18n.getMessage("m9"),
        chrome.i18n.getMessage("m10"),
        chrome.i18n.getMessage("m11"),
        chrome.i18n.getMessage("m12")
    ];
    var dnames=[
        chrome.i18n.getMessage("d1"),
        chrome.i18n.getMessage("d2"),
        chrome.i18n.getMessage("d3"),
        chrome.i18n.getMessage("d4"),
        chrome.i18n.getMessage("d5"),
        chrome.i18n.getMessage("d6"),
        chrome.i18n.getMessage("d7")
    ];
    
    var ddat=new Date();
    var ho=new Date(ddat.getFullYear(),ddat.getMonth(),ddat.getDate());
    //var ho=new Date(2012,11,7);//adviento
    //var ho=new Date(2013,11,26);//navidad
    //var ho=new Date(2013,0,26);//tiempo ordinario 1
    //var ho=new Date(2013,2,25);//cuaresma
    //var ho=new Date(2013,4,1);//pascua
    //var ho=new Date(2013,7,10);//tiempo ordinario 2   
    var year=ddat.getFullYear();
    var radius=prefs.getInt("radius");
    
    var tr={
        e:"s",
        lang:chrome.i18n.getMessage("l"),
        week:chrome.i18n.getMessage("week"),
        days:chrome.i18n.getMessage("days"),
        month:chrome.i18n.getMessage("month"),
        event:chrome.i18n.getMessage("event"),
        prefix:chrome.i18n.getMessage("urlprefix"),
        cyna:{
            adv:chrome.i18n.getMessage("adv"),
            nav:chrome.i18n.getMessage("nav"),
            ord1:chrome.i18n.getMessage("ord1"),
            cua:chrome.i18n.getMessage("cua"),
            pas:chrome.i18n.getMessage("pas"),
            ord2:chrome.i18n.getMessage("ord2")
            },
        special_dates_text:{
        today:chrome.i18n.getMessage("today"),
        palmsun:chrome.i18n.getMessage("palmsun"),
        goodfri:chrome.i18n.getMessage("goodfri"),
        penteco:chrome.i18n.getMessage("penteco")
        }
    };
                
    var anionum=((year%3===0)?3:Math.ceil(year%3));
    var anios=["","A","B","C"];
    var atipo=anios[anionum];
    var ddst=ho.toISOString().substring(0,10);
    
    
    var mgd=document.getElementById("cathlitgadgetd");
        mgd.style.textAlign="center";
        mgd.innerHTML='<div id="date"></div>';
        
    var dt=go();
    document.body.style.backgroundColor="white";
    //document.body.style.backgroundImage="url(images/t/"+dt.t[ho.getTime()]+".jpg)";
    document.body.style.backgroundRepeat="no-repeat";
    
    var ah1=document.createElement("a");
    var h1=document.createElement("h1");
        h1.appendChild(document.createTextNode(chrome.i18n.getMessage("lity")+' "'+atipo+'" '+ dt.c));
    var href="http://www.vercalendario.info/"+to_ascii(chrome.i18n.getMessage("l")+"/"+chrome.i18n.getMessage("event")+"/"+chrome.i18n.getMessage("urlprefix")+"-"+chrome.i18n.getMessage("year")+"-"+chrome.i18n.getMessage("calendar")+"-"+year)+".html";
        ah1.href=href;
        ah1.onclick=function(){
            openurl(this.href);
        };
        ah1.appendChild(h1);
    var h3=document.createElement("h3");
        h3.className=dt.t[ho.getTime()];
        h3.appendChild(document.createTextNode(chrome.i18n.getMessage("today")+': '+ddst+' - '+chrome.i18n.getMessage(""+dt.t[ho.getTime()])));
    var ah3=document.createElement("a");
        ah3.href='http://www.vercalendario.info/'+chrome.i18n.getMessage("todayurl");
        ah3.onclick=function(){
            openurl(this.href);
        };
        ah3.appendChild(h3);
    mgd.appendChild(ah1);
    mgd.appendChild(ah3);

    setTimeout(
        function(){
            show(document.getElementById("s"));
        },1000);


var t1=null;
function show(e){
    if(e.style.opacity < 0.9){
        s.style.opacity=(s.style.opacity*1)+0.05;
        t1=setTimeout(show, 100, e);
    }else{
        clearTimeout(t1);
    }
}

function openurl(url){
    if(url){
        chrome.tabs.create({'url': url});
    }else{
        chrome.tabs.create({'url': 'http://www.vercalendario.info/'+chrome.i18n.getMessage("l")+'/'});
    }
}
function go(){var d_t=[];function l(a){return document.createElementNS("http://www.w3.org/2000/svg",a)}function c(a,c,b){a.setAttributeNS(null,c,b)}function N(a){for(var c="\u00e1\u00e9\u00ed\u00f3\u00fa\u00e7\u00ff\u00f1\u00e3\u1ebd\u0129\u00f5\u0169\u00e2\u00ea\u00ee\u00f4\u00fb\u00fc\u00e0\u00e8\u00ec\u00f2\u00f9\u00e4\u00eb\u00ef\u00f6\u00fc\u00c1\u00c9\u00cd\u00d3\u00da\u00c7\u0178\u00d1\u00c3\u1ebc\u0128\u00d5\u0168\u00c2\u00ca\u00ce\u00d4\u00db\u00dc\u00c0\u00c8\u00cc\u00d2\u00d9\u00c4\u00cb\u00cf\u00d6\u00dc".split(""),
b="aeioucynaeiouaeiouuaeiouaeiouAEIOUCYNAEIOUAEIOUUAEIOUAEIOU_".split(""),d=0;d<c.length;d++)a=a.replace(c[d],b[d]);return a.toLowerCase()}function O(a,b){(16777216+16777215*Math.random()).toString(16).substr(1,6);var d=new Date(b.getTime());d.setDate(d.getDate()-1);var e;d.setHours(0,0,0);d.setDate(d.getDate()+0-(d.getDay()||7));var w=new Date(d.getFullYear(),0,1),w=Math.ceil(((d-w)/864E5+1)/7);e=[d.getFullYear(),w];var w=e[1],g=e[0],h=l("path");c(h,"class","w-w w-"+w);r=s-(A+a*x);t=s-A;var f=m+
y*Math.cos(r*Math.PI/180),j=k+y*Math.sin(r*Math.PI/180),n=m+y*Math.cos(t*Math.PI/180),p=k+y*Math.sin(t*Math.PI/180);c(h,"d","M "+m+" "+k+" L "+f+" "+j+" A "+y+" "+y+" 0 0 1 "+n+" "+p+" z");var q=l("path");c(q,"id","wtp"+w+"-"+g);c(q,"d","M "+f+" "+j+" A "+y+" "+y+" 0 0 1 "+n+" "+p);F.appendChild(q);f=l("text");f.wnum=e[1];f.wy=e[0];c(f,"class","wte");c(f,"dy","20px");f.onmouseover=function(){for(var a=document.getElementById("text_info");a.firstChild;)a.removeChild(a.childNodes[0]);var c=document.createTextNode(tr.week+
" "+this.wnum+" [ "+this.wy+" ]");a.appendChild(c)};e=l("textPath");c(e,"startOffset","50%");c(e,"class","wtp");e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#wtp"+w+"-"+g);g=l("tspan");c(g,"class","wtsp");g.appendChild(document.createTextNode(""+w));e.appendChild(g);f.appendChild(e);G[G.length]=f;h.year=d.getFullYear();h.week=w;H[H.length]=h}function P(a,b,d){var e=new Date(d.getTime());e.setDate(e.getDate()-1);d=l("path");c(d,"class","m-m m-m"+a);r=s-(A+b*x);t=s-A;var f=m+z*Math.cos(r*
Math.PI/180)+360*E,g=k+z*Math.sin(r*Math.PI/180)+360*E,h=m+z*Math.cos(t*Math.PI/180),j=k+z*Math.sin(t*Math.PI/180);c(d,"d","M "+m+" "+k+" L "+f+" "+g+" A "+z+" "+z+" 0 0 1 "+h+" "+j+" z");if(18<b){var n=l("path");c(n,"id","mtp"+a);c(n,"d","M "+f+" "+g+" A "+z+" "+z+" 0 0 1 "+h+" "+j);F.appendChild(n);f=l("text");f.month=e.getMonth();f.year=e.getFullYear();f.daycount=b;f.onmouseover=function(){for(var a=document.getElementById("text_info");a.firstChild;)a.removeChild(a.childNodes[0]);var c=document.createTextNode(mnames[this.month]+
" "+e.getFullYear()+", "+b+" "+tr.days);a.appendChild(c)};f.onclick=function(){var lcc="http://www.vercalendario.info/"+N(tr.lang+"/"+tr.event+"/"+tr.prefix+"-"+tr.month+"-"+mnames[this.month]+"-"+this.year+".html");chrome.tabs.create({'url': lcc});};c(f,"class","mte");c(f,"dy","20px");g=l("textPath");c(g,"startOffset","50%");c(g,"class","mtp");g.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#mtp"+a);h=l("tspan");c(h,"class","mtsp");h.appendChild(document.createTextNode(mnames[a].substring(0,3)+" "+e.getFullYear()));
g.appendChild(h);f.appendChild(g);I[I.length]=f}J[J.length]=d}function Q(a){if(n[a.getTime()]){var b=l("path");c(b,"class","c-c c-"+n[a.getTime()].cycle);c(b,"id",n[a.getTime()].cycle);r=s-(A+n[a.getTime()].daycount*x-x);t=s-(A-x);var d=0;182<n[a.getTime()].daycount&&(d=1);var e=m+B*Math.cos(r*Math.PI/180)+360*E,f=k+B*Math.sin(r*Math.PI/180)+360*E,g=m+B*Math.cos(t*Math.PI/180),h=k+B*Math.sin(t*Math.PI/180);c(b,"d","M "+m+" "+k+" L "+e+" "+f+" A "+B+" "+B+" 0 "+d+" 1 "+g+" "+h+" z");var j=l("path");
c(j,"id","ctp"+n[a.getTime()].cycle);c(j,"d","M "+e+" "+f+" A "+B+" "+B+" 0 "+d+" 1 "+g+" "+h);F.appendChild(j);d=l("text");c(d,"class","cte");d.cycle=n[a.getTime()].cycle;d.daycount=n[a.getTime()].daycount;d.onmouseover=function(){for(var a=document.getElementById("text_info");a.firstChild;)a.removeChild(a.childNodes[0]);var b=document.createTextNode(tr.cyna[this.cycle]+", "+this.daycount+" "+tr.days);a.appendChild(b)};e=l("textPath");c(e,"startOffset","50%");f="#ctp"+n[a.getTime()].cycle;e.setAttributeNS("http://www.w3.org/1999/xlink",
"xlink:href",f);f=l("tspan");f.appendChild(document.createTextNode(tr.cyna[n[a.getTime()].cycle].toUpperCase()));e.appendChild(f);d.appendChild(e);K[K.length]=d;b.daycount=n[a.getTime()].daycount;b.cycle=n[a.getTime()].cycle;L[L.length]=b}}var s=0,f=ho.getFullYear(),j=0.7*radius,y=0.8*radius,z=0.9*radius,B=0.95*radius,m=radius,k=radius,s=0>!chrome.i18n?360:0,d=function(a){a=new Date(a-1,11,25);for(var b=0,c=0;;){0===a.getDay()&&++b;if(4<=b)break;a.setDate(a.getDate()-1);if(1E3<
c)break;c++}return a},e=d(f),a=d(f+1);if(ho.getTime()<a.getTime()){d_t["c"]=(f-1)+"-"+(f);}ho.getTime()>=a.getTime()&&(d_t["c"]=f+"-"+(f+1),++f,e=a,a=d(f+1));var b=new Date(e.getTime()),C=0,v=0,p="adv",d=[],n=[],q=1,u=0,h;h=Math.floor(f/100);var D=f-19*Math.floor(f/19),g=h-Math.floor(h/4)-Math.floor((h-Math.floor((h-17)/25))/3)+19*D+15,g=g-30*Math.floor(g/30),g=g-Math.floor(g/28)*(1-Math.floor(g/28)*Math.floor(29/(g+1))*Math.floor((21-D)/11));h=f+Math.floor(f/4)+g+2-h+Math.floor(h/4);h-=7*Math.floor(h/7);g-=h;h=3+Math.floor((g+40)/44);h=new Date(f,h-1,g+28-31*Math.floor(h/
4));D=new Date(h.getTime());D.setDate(D.getDate()-47);g=new Date(h.getTime());g.setDate(g.getDate()+49);var M=new Date(f,0,6),f=new Date(f-1,11,25),E=0;for(document.getElementById("date")||E++;b.getTime()<a.getTime();)b.getTime()===ho.getTime()&&(v=C),d[b.getTime()]=p,0===b.getDay()&&++u,b.getTime()===g.getTime()?(n[b.getTime()]={cycle:"pas",daycount:q},q=0,p="ord2",u=0):b.getTime()===h.getTime()?(n[b.getTime()]={cycle:"cua",daycount:q},q=0,p="pas",u=0):b.getTime()===D.getTime()?(n[b.getTime()]=
{cycle:"ord1",daycount:q},q=0,p="cua",u=0):"adv"===p?b.getTime()===f.getTime()&&(n[b.getTime()]={cycle:"adv",daycount:q},q=0,p="nav",u=0):"nav"===p&&(b.getTime()>M.getTime()&&0===b.getDay())&&(n[b.getTime()]={cycle:"nav",daycount:q},q=0,p="ord2",u=0),b.setDate(b.getDate()+1),C++,q++;n[(new Date(a.getTime())).setDate(a.getDate()-1)]={cycle:"ord2",daycount:q-1};d_t["t"]=d;b=new Date(h.getTime());b.setDate(b.getDate()-7);p=new Date(h.getTime());p.setDate(p.getDate()-2);f=[];f[b.getTime()]="palmsun";f[p.getTime()]=
"goodfri";f[g.getTime()]="penteco";f[ho.getTime()]="today";for(var x=360/C,b=new Date(e.getTime()),g=b.getMonth(),p=0,C=[],H=[],J=[],L=[],G=[],I=[],K=[],F=l("defs"),u=q=0,r,t=0,A=90+v*x+x/2;360>Math.round(s);)Q(b),g!==b.getMonth()&&(P(g,p,b),p=0),0===b.getDay()&&(O(u,b),u=0),b.getTime()>=a.getTime()&&(b=new Date(e.getTime()),b.setDate(e.getDate()-1)),r=s-A,t=s-(A-x),v=l("path"),g=m+j*Math.cos(r*Math.PI/180),h=k+j*Math.sin(r*Math.PI/180),D=m+j*Math.cos(t*Math.PI/180)+360*E,M=k+j*Math.sin(t*Math.PI/
180)+360*E,c(v,"d","M "+m+" "+k+" L "+g+" "+h+" A "+j+" "+j+" 0 0 1 "+D+" "+M+" z"),c(v,"class"," d-d d-"+(d[b.getTime()]?d[b.getTime()]:"ad")+"  d-md"+b.getMonth()+"-"+b.getDate()+"  d-my"+b.getMonth()+"-"+b.getFullYear()+" d-ymd"+b.getFullYear()+"-"+b.getMonth()+"-"+b.getDate()+" "),f[b.getTime()]&&c(v,"id",f[b.getTime()]),v.onclick=function(){var lcc="http://www.vercalendario.info/"+N(tr.lang+"/"+tr.event+"/"+tr.prefix+"-"+this.date.getDate()+"-"+mnames[this.date.getMonth()]+"-"+this.date.getFullYear()+
".html");chrome.tabs.create({'url': lcc});},v.onmouseover=function(){for(var a=dnames[0===this.date.getDay()?6:this.date.getDay()-1],b=document.getElementById("text_info");b.firstChild;)b.removeChild(b.childNodes[0]);a=document.createTextNode(a+", "+this.date.toISOString().substring(0,10)+(this.id?" [ "+tr.special_dates_text[this.id]+" ]":""));b.appendChild(a)},v.date=new Date(b.getTime()),C[C.length]=v,p++,g=b.getMonth(),s+=x,b.setDate(b.getDate()+1),u++,q++;P(g,p,b);O(u,a);e=l("svg");c(e,"id","svglit");e.setAttributeNS("http://www.w3.org/2000/xmlns/",
"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:cc","http://creativecommons.org/ns#");e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:dc","http://purl.org/dc/elements/1.1/");e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink");e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/svg");c(e,"version","1.1");c(e,"width",2*radius);c(e,"height",2*radius);e.appendChild(F);
for(a=0;a<L.length;a++)e.appendChild(L[a]);for(a=0;a<K.length;a++)e.appendChild(K[a]);a=l("circle");c(a,"cx",m);c(a,"cy",k);c(a,"r",z);c(a,"id","mci");e.appendChild(a);for(a=0;a<J.length;a++)e.appendChild(J[a]);for(a=0;a<I.length;a++)e.appendChild(I[a]);a=l("circle");c(a,"cx",m);c(a,"cy",k);c(a,"r",y);c(a,"id","wci");e.appendChild(a);for(a=0;a<H.length;a++)e.appendChild(H[a]);for(a=0;a<G.length;a++)e.appendChild(G[a]);a=l("circle");c(a,"cx",m);c(a,"cy",k);c(a,"r",j);c(a,"id","dci");e.appendChild(a);
for(a=0;a<C.length;a++)e.appendChild(C[a]);a=l("path");c(a,"id","cmn");d=0.2*j;b=0.2*d;c(a,"d","M "+(m-d/2)+" "+(k-d/2+b)+" L "+(m+d/2)+" "+(k+d/2-b)+" M "+(m+d/2)+" "+(k-d/2+b)+" L "+(m-d/2)+" "+(k+d/2-b)+" M "+m+" "+(k-d)+" V "+(k+0.7*d)+" M "+m+" "+(k-d)+" C "+(m+d/2)+" "+(k-d)+" "+(m+d/2)+" "+(k-d/2)+" "+m+" "+(k-d/2));c(a,"stroke","black");c(a,"stroke-width","5px");c(a,"fill","transparent");e.appendChild(a);a=l("g");d=l("rect");c(d,"id","rect_info");c(d,"x",m-0.8*j);c(d,"y",k-j/3);c(d,"width",
1.6*j);c(d,"height","200");b=l("text");c(b,"x",m-0.8*j);c(b,"y",k-j/3);c(b,"id","text_info");a.appendChild(d);a.appendChild(b);e.appendChild(a);j=l("text");c(j,"x",2*radius-160);c(j,"y",2*radius-20);c(j,"id","copyright");j.appendChild(document.createTextNode("\u00a9 vercalendario.info "+(new Date).getFullYear()));e.appendChild(j);document.getElementById(tr.e).appendChild(e);return d_t;};function to_ascii(s){var a=[" ","á","é","í","ó","ú","ç","ÿ","ñ","ã","ẽ","ĩ","õ","ũ","â","ê","î","ô","û","ü","à","è","ì","ò","ù",     "ä","ë","ï","ö","ü","Á","É","Í","Ó","Ú",  "Ç","Ÿ","Ñ",    "Ã","Ẽ","Ĩ","Õ","Ũ",    "Â","Ê","Î","Ô","Û","Ü",    "À","È","Ì","Ò","Ù",     "Ä","Ë","Ï","Ö","Ü" ];var b=["_","a","e","i","o","u","c","y","n",    "a","e","i","o","u",    "a","e","i","o","u","u",    "a","e","i","o","u",     "a","e","i","o","u", "A","E","I","O","U",  "C","Y","N",    "A","E","I","O","U",    "A","E","I","O","U","U",    "A","E","I","O","U",     "A","E","I","O","U","_"];for(var i=0;i<a.length;i++){s=s.replace(a[i],b[i]);}return s.toLowerCase();}
    